package com.chencs.coupon.wk;

import com.alibaba.druid.util.StringUtils;
import com.alibaba.fastjson.JSON;
import com.chencs.biz.Common;
import com.chencs.coupon.hwc.HWCRootBean;
import com.chencs.coupon.hwc.HWCUtils;
import com.chencs.utils.CRequest;
import com.chencs.vo.biz.password.ApplyCommission;
import org.jsoup.Jsoup;

import java.util.Map;

public class WKUtils {


    /**
     * 申请高佣金
     * @param pid
     * @param mid
     * @return
     */
    public  static ApplyCommission getCouponID(String pid,String mid){
        String mmid = mid;
        ApplyCommission commission = null;
        String str;
        if(com.alibaba.druid.util.StringUtils.isEmpty(mmid)){
            mmid = Common.PID;
        }
        try {
            if(!StringUtils.isEmpty(pid)){
                if(StringUtils.isNumber(pid)){
                    org.jsoup.nodes.Document res = Jsoup.connect("http://tkapi.apptimes.cn/coupon?appkey=93kc2a4b&pid="+mmid+"&good_id="+pid)
                            .timeout(10000).ignoreContentType(true).get();
                    str = res.body().text();
                    commission = JSON.parseObject(str,ApplyCommission.class);
                }else{
                    commission.setErrcode("-1");
                    commission.setErrmsg("1pid不是数字");
                }
            }else{
                commission.setErrcode("-1");
                commission.setErrmsg("pid空");
            }
        }catch (Exception e){
            return null;
        }
        return commission;
    }

    /**
     * 检测券是否有效
     * @param url
     * @return
     * retStatus 0 有效
     */
    public  static EffectiveBean geEffective(String url){
        Map<String, String> map = CRequest.URLRequest2(url);
        EffectiveBean effectiveBean = null;
        String estr= map.get("e");
        String str;
      try {
          org.jsoup.nodes.Document res = Jsoup.connect("http://tkapi.apptimes.cn/coupon/info?appkey=93kc2a4b&e="+estr).timeout(10000).ignoreContentType(true).get();
          str = res.body().text();
          effectiveBean = JSON.parseObject(str,EffectiveBean.class);
          effectiveBean.setEstr(estr);
      }catch (Exception e){
          return null;
      }
      return effectiveBean;
    };


}
